<?php

use yii\helpers\Html;
use yii\widgets\ActiveForm;
use yii\helpers\ArrayHelper;
use common\models\business\BusinessAdress;
use yii\web\JsExpression;
/* @var $this yii\web\View */
/* @var $model common\models\business\BusinessPut */
/* @var $form yii\widgets\ActiveForm */
?>

<div class="row">
    <div class="col-lg-12">
        <section class="panel">
        <div class="panel-body">
            <div class="adv-table editable-table ">
                <div class="business-put-form">
                    <?php $form = ActiveForm::begin([
                        'options' => ['class' => 'form-horizontal','enctype' => 'multipart/form-data'],
                        'fieldConfig' => [
                            'template' => "<div class='col-xs-3 col-sm-2 text-right'>{label}</div><div class='col-xs-9 col-sm-7'>{input}</div><div class='col-xs-12 col-xs-offset-3 col-sm-3 col-sm-offset-0'>{error}</div>",
                        ]
                    ]); ?>

                        <?= $form->field($model, 'person')->widget(\kartik\select2\Select2::className(), [
                            'options' => ['placeholder' => '请输入业务员姓名 ...'],
                            'initValueText'=>$model->putperson?$model->putperson->name:'',
                            'pluginOptions' => [
                                'allowClear' => true,
                                'minimumInputLength' => 1,//重要
                                'language' => [
                                    'errorLoading' => new JsExpression("function () { return '正在查找.'; }"),
                                ],
                                'ajax' => [
                                    'url' => '/business/search/search-person',
                                    'dataType' => 'json',
                                    'data' => new JsExpression('function(params) { return {q:params.term}; }'),
                                    'cache' => true
                                ],
                                'width' => '400px',
                                'escapeMarkup' => new JsExpression('function (markup) { return markup; }'),
                                'templateResult' => new JsExpression('function(res) { return res.text; }'),
                                'templateSelection' => new JsExpression('function (res) { return res.text; }'),
                            ],
                        ]);
                        ?>


                    <?= $form->field($model, 'num')->textInput() ?>


                        <?= $form->field($model, 'cunid')->dropDownList(ArrayHelper::map(BusinessAdress::find()->where('type=:type',['type'=>BusinessAdress::TYPE_CUN])->asArray()->all(),'id','name')) ?>

                        <?= $form->field($model, 'no')->textInput(['maxlength' => true]) ?>


                    <div class="form-group">
                        <?= Html::submitButton($model->isNewRecord ? '确认提交' : '确认更新', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
                    </div>
                    <?php ActiveForm::end(); ?>
                </div>
            </div>
        </div>
    </section>
</div>
</div>